#ifndef DISPATCHER_H
#define DISPATCHER_H

#include <QObject>
#include "macrohelper.h"
#include "cargo.h"
#include <vector>
#include <queue>
#include <mutex>
#include <memory>
#include <condition_variable>
#include "ship.h"
#include <QTimer>

// 调度员
class Dispatcher : public QObject
{
    Q_OBJECT
    SINGLETON(Dispatcher)
    QML_WRITABLE_PROPERTY(bool, isOnDuty, IsOnDuty)
public:
    enum Status {
             IDLE = 0,
             WORKING,
    };
    explicit Dispatcher(QObject *parent = nullptr);

    void inputApplyShipMessage(const QString ship_id);

    std::mutex& getQueMutex();
    std::shared_ptr<Cargo> distributeCargo();
    std::condition_variable& getCond();

signals:

public slots:

    void notifyOnDuty();

    void onShipTransportAway(const Ship* ship);


    void checkApplyMessage();

private:
    std::mutex m_que_mtx;
    std::queue<QString> m_apply_messsage;
    Status m_status;
    QTimer* m_timer;
    std::condition_variable m_cond;
};

#endif // DISPATCHER_H
